unit search;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TFSearch = class(TForm)
    searchType: TComboBox;
    Label1: TLabel;
    groupSFF: TGroupBox;
    Label2: TLabel;
    group: TEdit;
    Label3: TLabel;
    image: TEdit;
    groupAIR: TGroupBox;
    airAnimList: TComboBox;
    Label4: TLabel;
    btnSearch: TBitBtn;
    procedure btnSearchClick(Sender: TObject);
    procedure imageKeyPress(Sender: TObject; var Key: Char);
    procedure groupKeyPress(Sender: TObject; var Key: Char);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure ifClose( Key : char);
    procedure searchTypeKeyPress(Sender: TObject; var Key: Char);
    procedure btnSearchKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure searchTypeSelect(Sender: TObject);
    procedure airAnimListKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FSearch: TFSearch;

implementation

uses
sprites,mugen;

{$R *.dfm}

procedure TFSearch.btnSearchClick(Sender: TObject);
var
    index   : integer;
begin
    if ( searchType.text = 'SFF') then
    begin
      if ( ( group.Text <> '' ) and ( image.Text <> '' ) ) then
      begin
        index := FormSprites.arqsff.FindImg( strtoint2( group.Text ), strtoint2( image.Text ) );

        if ( index = -1 ) then
        begin
          showmessage('Impossible to find image!');
        end else
        begin
          FormSprites.selimg.position := index;
          FormSprites.selimg.onchange( nil );
        end;

        close();

      end else
      begin
        showmessage('Inform a group and image to search!');
      end;
    end
    else
    if ( searchType.Text = 'AIR') then
    begin
      if ( airAnimList.text <> '' ) then
      begin
        index := FormSprites.AirFile1.find( strtoint2( airAnimList.text )) ;
        if ( index = -1 ) then
        begin
          showmessage('Impossible to find action!');
        end else
        begin
          FormSprites.selanim.position := index;
          FormSprites.selanim.onchange( nil );
        end;
      end;
    end;

end;

procedure TFSearch.imageKeyPress(Sender: TObject; var Key: Char);
begin
  if ( Key = #13 ) then
  begin
    Key := #0;
    btnSearch.OnClick(nil);
  end;
  ifClose(Key);
end;

procedure TFSearch.groupKeyPress(Sender: TObject; var Key: Char);
begin
  if ( Key = #13 ) then
  begin
    Key := #0;
    image.SetFocus();
  end;
  ifClose(Key);
end;

procedure TFSearch.FormKeyPress(Sender: TObject; var Key: Char);
begin
  ifClose(Key);
end;

procedure TFSearch.ifClose( Key : char );
begin
  if ( Key = #27 ) then
  begin
    close();
  end;
end;


procedure TFSearch.searchTypeKeyPress(Sender: TObject; var Key: Char);
begin
  ifClose(Key);
end;

procedure TFSearch.btnSearchKeyPress(Sender: TObject; var Key: Char);
begin
  ifClose(Key);
end;

procedure TFSearch.FormShow(Sender: TObject);
begin
    if ( FormSprites.pagecontrol1.ActivePage = FormSprites.AIR ) then
    begin
      searchType.ItemIndex := 1;
    end else
    if ( FormSprites.pagecontrol1.ActivePage = FormSprites.SFF ) then
    begin
      searchType.ItemIndex := 0;
    end;

    AirAnimList.items := FormSprites.Airfile1.getList; // update anim list
    searchType.OnSelect( nil );
end;

procedure TFSearch.searchTypeSelect(Sender: TObject);
begin
  groupSFF.Visible := false;
  groupAIR.Visible := false;

  if ( searchType.Text = 'SFF') then
  begin
    groupSFF.Top := 40;
    groupSFF.Visible := true;
  end
  else if ( searchType.Text = 'AIR') then
  begin
    groupAIR.Top := 40;
    groupAIR.Visible := true;
  end;
end;

procedure TFSearch.airAnimListKeyPress(Sender: TObject; var Key: Char);
begin
  if ( Key = #13 ) then
  begin
    Key := #0;
    btnSearch.OnClick(nil);
  end;
  ifClose(Key);
end;

end.
